package interfaces.tables;

import networking.messages.syncMessages.ValueType;

import org.fenggui.decorator.border.PlainBorder;
import org.fenggui.util.Color;
import org.fenggui.util.Spacing;

import fileHandling.language.interfaces.ScoreBoard;

import logic.common.player.Player;
import logic.common.player.playerListeners.PlayerValueListener;
import logic.status.StatusChangedEvent;

public class TeamTableEntry extends TableEntry {
	
	protected Player player;
	
	public TeamTableEntry(int width, int height, int x, Player player, TeamTable table) {
		super(width, height, x, table);
		this.player = player;
		
		int spacing = 1;
		getAppearance().setBorder(new Spacing(spacing, spacing));
		getAppearance().add(new PlainBorder(Color.DARK_GRAY, spacing));
		
		setValueOf(ScoreBoard.Name, player.getName());
		setValueOf(ScoreBoard.Kills, player.getKills() + "");
		setValueOf(ScoreBoard.Deaths, player.getDeaths() + "");
		setValueOf(ScoreBoard.Ping, player.getPing() + "");
		
		player.addPlayerValueListener(new PlayerValueListener() {
			@Override
			public void valueChanged(StatusChangedEvent event) {
				if(event.getType() == ValueType.Kills) setValueOf(ScoreBoard.Kills, event.getIntValue() + "");
				else if(event.getType() == ValueType.Deaths) setValueOf(ScoreBoard.Deaths, event.getIntValue() + "");
				else if(event.getType() == ValueType.Ping) setValueOf(ScoreBoard.Ping, event.getIntValue() + "");
			}
		});
		
		setSelected(false);
	}
	
	@Override
	public Color getNormalBGColor() {
		if(player == player.getTeam().getGame().getCurrentPlayer()) return Color.WHITE;
		return Color.TRANSPARENT;
	}
	
	@Override
	public Color getSelectedBGColor() { return Color.TRANSPARENT; }
}